package com.yhwch.fun.service;

import com.yhwch.fun.dao.InsuDAO;
import com.yhwch.fun.domain.ExecuteParam;
import com.yhwch.fun.domain.InsuDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class ImportInsuTableService extends ImportDataFromFileAbstract<InsuDO> {

    @Autowired
    InsuDAO insuDAO;
    @Autowired
    TaskExecService taskExecService;

    @Override
    int insert(InsuDO param) {
        return insuDAO.insert(param);
    }

    @Override
    InsuDO select(Map<String, Object> param) {
        return insuDAO.select((String)param.get("1"));
    }

    @Override
    Map<String, Object> genSelectParam(InsuDO insuDO) {
        Map<String, Object> map = new HashMap<>();
        map.put("1",insuDO.getInName());
        return map;
    }

    @Override
    InsuDO parseT(String t) {
        String[] params = t.split("~");
        InsuDO back = new InsuDO();
        back.setInName(params[0]);
        back.setInSex(params[1]);
        return back;
    }

    @Override
    ExecuteParam getExecuteParam() {
        ExecuteParam executeParam = new ExecuteParam();
        executeParam.setTaskExecService(taskExecService);
        executeParam.setKeyName("insu_d");
        executeParam.setPath("/Users/zhiaiyahong/Upload/");
        executeParam.setChildFileName("child_insu_");
        executeParam.setFileNameSuffix(".csv");
        executeParam.setFatherFileName("insu_208.csv");
        executeParam.setCharsetName("UTF-8");
        executeParam.setChildFileSize(1024*1024*3);
        executeParam.setSplitStr("~");
        executeParam.setSplitCount(2);
        return executeParam;
    }
}
